package cqie.cn.frame.utils;

import cqie.cn.frame.exception.ExceptionEnum;

/**
 * @author 王林
 * @version 1.0
 * @date 2021-09-06 周一
 * @time 10:46
 * @description
 */
public class RetJsonUtils {

    public static RetJson success() {

        return success(200, "操作成功", null, 0);
    }

    public static RetJson success(String msg) {

        return success(200, msg, null, 0);
    }

    public static RetJson success(Object object) {

        return success(200, "查询成功", object, 0);
    }

    public static RetJson success(String msg, Object object) {

        return success(200, msg, object, 0);
    }

    public static RetJson success(String msg, Object object, long count) {

        return success(200, msg, object, count);
    }

    public static RetJson success(Object object, long count) {

        return success(200, "操作成功", object, count);
    }

    private static RetJson success(int code, String message, Object object, long count) {

        RetJson result = new RetJson<>();
        result.setCode(code);
        result.setMsg(message);
        result.setData(object);
        result.setCount(count);

        return result;
    }

    public static RetJson error() {

        RetJson result = new RetJson<>();
        result.setCode(201);
        result.setMsg("操作失败");

        return result;
    }

    public static RetJson error(String message) {

        RetJson result = new RetJson<>();
        result.setCode(201);
        result.setMsg(message);

        return result;
    }

    public static RetJson error(int code, String message) {

        RetJson result = new RetJson<>();
        result.setCode(code);
        result.setMsg(message);

        return result;
    }

    public static RetJson error(ExceptionEnum exceptionEnum) {

        RetJson result = new RetJson<>();
        result.setCode(exceptionEnum.getCode());
        result.setMsg(exceptionEnum.getMsg());

        return result;
    }
}